package operation;

import book.*;

import java.awt.*;
import java.util.Scanner;

public class Modify implements IOperation{
    Mod[] mod = new Mod[] {
            new ModName(),
            new ModAuthor(),
            new ModPrice(),
            new ModCond()
    };
    public void menu () {
        System.out.println("1.书名");
        System.out.println("2.作者");
        System.out.println("3.价格");
        System.out.println("4.借阅情况");
        System.out.print("请输入对应编号：");
    }


    @Override
    public void work(Booklist booklist) {
        System.out.print("请输入要修改的图书名：");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();
        Book book = booklist.getBook(0);
        for (int i = 0; i < booklist.getNum(); i++) {
            book = booklist.getBook(i);
            if (book.getName().equals(name)) {
                this.menu();
                int c = 0;
                c = scan.nextInt();
                Mod mod1 = mod[c - 1];
                mod1.modify(book);
                break;
            } else if (i == booklist.getNum()-1) {
                System.out.println("没有找到相关图书，请重新尝试。");
            }
        }
    }
}
